//
//  LXPresentationController.m
//  灵秀
//
//  Created by 李田 on 17/3/19.
//  Copyright © 2017年 tianyao. All rights reserved.
//

#import "LXPresentationController.h"

@implementation LXPresentationController


- (void)containerViewWillLayoutSubviews
{
    [super containerViewWillLayoutSubviews];
    
    // 1.获取containerView
    UIView *containerView = self.containerView;
    
    
    // 2.拿到第二个控制器的View
    UIView *toView = self.presentedView;
    
    //自己手动添加
    [containerView addSubview:toView];
    
    // 3.修改第二控制器的View大小
    [toView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.equalTo(containerView);
        make.height.mas_equalTo(320);
    }];
    
    // 4.添加蒙版View
    UIView *dimView = [[UIView alloc]init];
    dimView.backgroundColor = [UIColor blackColor];
    dimView.alpha = 0.3;
    [containerView insertSubview:dimView atIndex:0];
    
    [dimView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.top.bottom.equalTo(containerView);
    }];
    
    // 添加 tap的手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    
    [dimView addGestureRecognizer:tap];
}

#pragma mark - 点击透明的位置 实现 dimiss
- (void)tap:(UITapGestureRecognizer *)sender{

    [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}

@end
